// pages/order/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading: 0,
    page: 1,
    accountStatus:0,
    type:1,
    status: 0,
    lastpage: 0,
    listData: [],
    user_info: {},
    money: 0,
    partnerMoneyCount:0,
    account_frozen: 0,
    income: 0,
    serviceProviderCount: 0,
    storeCount: 0,
    listData: [],
    loaded: 0,
    page: 1,
    commission_shop:0,
  },

  init: function () {
    var that = this;
    app.api("apiv2/user/getStoreCount", function (res) {
      if (res.code != 200) {
        app.alert(res.msg);
        return;
      }
      that.setData({
        storeCount: res.data
      });
    });
    app.api("apiv2/user/getPartnerMoneyCount", function (res) {
      if (res.code != 200) {
        app.alert(res.msg);
        return;
      }
      that.setData({
        partnerMoneyCount: res.data
      });
    });

    
    this.getUserInfo();
  

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    if (options.status) {
      this.data.status = options.status;
      this.setData({ status: options.status });
    }
    app.getUserInfo((user_info) => {
      this.setData({ user_info: user_info });
      this.init();
    })
     

  },
  
  getUserInfo() {
    var that = this;
    app.api("api/user/info", { fields:"commission_nums,member_partner"}, function (res) {
      if (res.code != 200) {
        app.alert(res.msg);
        return;
      }

      that.setData({
        info: res.data,
        commission_shop: res.data && res.data.commission_nums && res.data.commission_nums.shop,
        account_frozen: res.data && res.data.member_partner && res.data.member_partner.account_frozen,
        accountStatus: res.data && res.data.member_partner && res.data.member_partner.status,
      });

    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.init();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

    this.getrecommend();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  unDoWithDraw: function () {
    this.setData({type:1});
  },
  withDraw: function () {
    this.setData({ type: 4 });
  },
  //充值
  doRecharge: function (e) {

    var that = this;
    var postData = e.detail.value;

    if (postData.name == "") {
      app.alert('真实姓名不能为空');
      return;
    }
    if (postData.account == "") {
      app.alert('支付宝帐号不能为空');
      return;
    }

    that.setData({ loading: 1, disabled: 1 });
    that.data.payloading = 1;
    wx.setStorageSync('name', postData.name);
    wx.setStorageSync('account', postData.account);
    app.api("/api/user/withDrawAccountFrozen", {
      name: postData.name,
      account: postData.account
    }, function (res) {
      if (res.code != 200) {
        app.alert(res.msg);
        that.data.payloading = 0;
        that.setData({ 'loading': 0, 'disabled': 0 });
        if (res.code == 3) {
          that.attention();
        }
        return false;
      }
      that.init();
      that.setData({ 'loading': 0, 'disabled': 0, type:1 });
    })
  },
})